package com.example.Controller;


import com.example.entity.SMSParameter;
import com.example.entity.Users;
import com.example.service.UserService;
import com.example.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * The type User controller.
 * @author XingGao
 */
@CrossOrigin //跨域
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * Gets .
     *
     * @param user the user
     * @return the
     */
    @PostMapping(value = "/login")
    public ResultData getuser(@RequestBody Users user) {

        return userService.UserLogin(user);
    }

    /**
     * Add user result data.
     *
     * @param user     the user
     * @param response the response
     * @return the result data
     */
    @PostMapping(value = "/register")
    public ResultData addUser(@RequestBody Users user, HttpServletResponse response) {
        return userService.addUser(user, response);
    }

    /**
     * Adduser 1 result data.
     *
     * @param parameter the parameter
     * @return the result data
     */
    @PostMapping(value = "/verification")
    public ResultData adduser1(@RequestBody SMSParameter parameter) {

        return userService.verification(parameter);
    }


    /**
     * Gets user.
     *
     * @param user    the user
     * @param request the request
     * @return the user
     */
    @PostMapping(value = "getuser")
    public ResultData getUser(@RequestBody Users user, HttpServletResponse request) {
        request.addCookie(new Cookie("message", "网站正式上线!!"));
        return userService.UserAuthentication(user);
    }

    /**
     * Gets user.
     *
     * @param user the user
     * @param file the file
     * @return the user
     */
    @PostMapping(value = "UpUserImg")
    public ResultData getUser(Users user, @RequestParam("file") MultipartFile file) {

        return userService.UserImg(user, file);
    }

    /**
     * Up user paw result data.
     *
     * @param users the users
     * @return the result data
     */
    @PostMapping(value = "UpUserPaw")
    public ResultData UpUserPaw(@RequestBody Users users) {

        return userService.RetrievePaw(users);
    }

    /**
     * Up data phone result data.
     *
     * @param users the users
     * @return the result data
     */
    @PostMapping(value = "UpDataPhone")
    public ResultData UpDataPhone(@RequestBody Users users) {
        return userService.UpDataPhone(users);
    }

    /**
     * Gets user all.
     *
     * @return the user all
     */
    @PostMapping(value = "getUserAll")
    public ResultData getUserAll() {

        return userService.GetUserAll();
    }

    /**
     * Del user result data.
     *
     * @param users the users
     * @return the result data
     */
    @PostMapping(value = "DelUserOne")
    public ResultData DelUser(@RequestBody Users users) {

        return userService.delUserByID(users);
    }

    /**
     * Sets user ju.
     *
     * @param users the users
     * @return the user ju
     */
    @PostMapping(value = "setUserJu")
    public ResultData setUserJu(@RequestBody Users users) {

        return userService.setUserJu(users);
    }

    /**
     * Sets notice.
     *
     * @param notice the notice
     * @return the notice
     */
    @PostMapping(value = "setNotice")
    public ResultData setNotice(@RequestBody Map<String, String> notice) {
        return userService.setNotice(notice.get("Notice"));
    }

    /**
     * Gets notice.
     *
     * @return the notice
     */
    @PostMapping(value = "getNotice")
    public ResultData getNotice() {
        return userService.getNotice();
    }

    /**
     * Up data user result data.
     *
     * @param users the users
     * @return the result data
     */
    @PostMapping(value = "UpDataUser")
    public ResultData UpDataUser(@RequestBody Users users) {
        return userService.UpDataUser(users);
    }

}

